<%@ page import="cn.ekgc.web166.entity.Student" %>
<%@ page import="cn.ekgc.web166.commons.DateUtils" %>
<%@ page import="cn.ekgc.web166.dao.StudentDao" %>
<%@ page import="cn.ekgc.web166.dao.StudentDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/18 0018
  Time: 16:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String name = request.getParameter("name");
    String gender = request.getParameter("gender");
    String bornday = request.getParameter("bornday");
    if(name!= null && name.trim().length()>=2 && name.trim().length()<7){
        Student student = new Student(name,gender, DateUtils.getDate(bornday,"yyyy-MM-dd"));
        //保存
        StudentDao dao = new StudentDaoImpl();
        dao.save(student);
        response.sendRedirect("doshowstudent.jsp?id="+student.getId());
    }else{
        //转发回添加页面
        request.setAttribute("error","名字长度在2-6之间");
        request.getRequestDispatcher("addstudent.jsp").forward(request,response);
    }
%>